from data.config.DefaultConfig import point_config
from effect.player.Player import Player
from effect.skills.loader import skillLoader
from entiys.map.mapMovePolicy import preinstall, mapMovePolicy
from entiys.methods.augument.SaveAttribute import SaveAttribute
from entiys.npc.NPCLoader import NPCLoader
from entiys.npc.NPCSave import NPCSave
from entiys.npc.NpcManagerWithFilter.NpcSaveWithFilter import NpcSaveWithFilter
from game_control.save.saveManager import SaveManager


def method_test():
    def filter_mindlt15(chara, attribute: dict):
        mind = attribute.get("智商")

        if mind is None:
            mind = 0
        return mind > 15

    npcLoader = NPCLoader(saveName="1689286429.7449932")
    for i in (npcLoader.getByMethod(filter_mindlt15)):
        print(i)


def attval_test():
    npcLoader = NPCLoader(saveName="1689286429.7449932")
    for i in (npcLoader.getByAttributeValue("地点", "雪神宫")):
        print(i)


def save_modification_byName():
    npcSave = NPCSave(saveName="1689351361.7538834")
    npcSave.setNpcAttributeByName(
        charaname="雪神",
        attribute="兽交",
        methodValue=lambda a: a.get("兽交") + 1
    )


def save_modification_byMethod():
    def filter_nodie_pk(npcname, attri: dict):
        return attri.get("是否处女") is False

    def add_dl(attr: dict):
        return True

    npcSave = NPCSave(saveName="1689351361.7538834")
    npcSave.setNpcAtttributeByMethod(
        method=filter_nodie_pk,
        attribute="是否处女",
        valueMethod=lambda b: add_dl(b)
    )


def npcSaveWithFilter_random_map():
    npcSave = NPCSave(saveName="1691768753.8807518")
    npcSaveWithFilter = NpcSaveWithFilter(npcSave)
    npcSaveWithFilter.randomMoveMap("雪神", _mapMovePolicy=preinstall.NOHOME())


def loadSave():
    saveAttribute = SaveAttribute("新存档")
    maps = saveAttribute.mapJSON()

    print(maps.map_data)
    print(maps.all_dy)


def readSkill():
    """
    加载技能
    :return:
    """
    savename = "1691865067.7327378"

    npcLoader = NPCLoader(saveName=savename)
    _self = npcLoader.getByName("雪神")
    _enemy = npcLoader.getByName("艾莉马特公主")

    _skillLoader = skillLoader(saveName=savename)
    _skillLoader.adapter()
    playscript = _skillLoader.render_text(skills_name='按住', self_chara=_self, enemy_chara=_enemy)
    print(playscript)


def preinstallfunc():
    print(preinstall.NOHOME(save=SaveAttribute('1691865067.7327378')).to_list())


def map():
    saveAttribute: SaveAttribute = SaveAttribute("1691865067.7327378")
    print(mapMovePolicy(saveAttribute=saveAttribute).to_list())


def newNPCRandom():
    savename = "1698048827.0176144"
    npcsave = NPCSave(saveName=savename)
    random = npcsave.newNPCRandom()
    random['name'] = "王三"
    npcsave.replaceCharajson(random, newname=True)

    npcLoader = NPCLoader(saveName=savename)


def GetHome(savename):
    save = SaveAttribute(saveName=savename)
    player = Player(saveAttribute=save)
    print(player.GetHomes())
    print(player.getAttribute("saveJson", "playername"))


def setValuePlayer(saveName):
    save = SaveAttribute(saveName)
    player = Player(saveAttribute=save)
    player.setAttribute("帅哥", "saveJson", "playername")


if __name__ == '__main__':
    savename = "新存档"
    setValuePlayer(savename)
